<div class="row animate fadeIn">
    <form class="form-horizontal" id="uom-form">
    <div class="ibox-title" style="border:none;"><h5 style="color: #00afef"><i>Add</i></h5>
        <div class="ibox-tools">    
             <button class="btn btn-primary btn-sm save-btn-tab" id="submit-uom">Save</button>
             <a id="cancel_add" class="btn btn-sm btn-outline btn-info cancel-btn-tab">Cancel</a>
        </div>
     </div>
     <div class="ibox-content">
        
            <div class="form-group">
                <label class="col-lg-2 control-label">Company</label>
                <div class="col-lg-4">
                    <input type="text" class="form-control" value ="<?php echo $this->session->userdata('comp_name'); ?>" readonly>
                    <input type="hidden" id="uom_cn" name="company_id" value="<?php echo $this->session->userdata('company_id'); ?>">
                </div>
             </div>
             <div class="form-group">
                <label class="col-lg-2 control-label">UOM Code</label>
                <div class="col-lg-2">
                    <input type="text" id="uom_c"class="form-control" name="uom_code">
                </div>
            </div>
            <div class="form-group">
                <label class="col-lg-2 control-label">Name</label>
                <div class="col-lg-3">
                    <input type="text" id="uom_n" class="form-control" name="uom_name">
                </div>
            </div>
            <div class="form-group"><label class="col-lg-2 control-label">Enable</label>
                <div class="col-lg-1">
                    <input type="checkbox" id="uom_cb" class="i-checks" name="uom_enabler" value="ok" checked>
                </div>
            </div>
        </form>
    </div>
 </div>
 <script>
    $(document).ready(function(){
            $('.i-checks').iCheck({
                    checkboxClass: 'icheckbox_square-green',
                    radioClass: 'iradio_square-green',
              });
            $("#uom-form").validate({
                 rules: {
                     company_name: {
                         required: true,
                         lettersonly: true
                     },
                     uom_code: {
                         required: true,
                         capitalonly: true
                     },
                     uom_name: {
                         required: true,
                         lettersonly: true
                     }
                 },
                 submitHandler: function(form){
                    $.ajax({
                        type: "POST",
                        url: "<?php echo base_url($this->session->userdata('forajax').'/insert_uom'); ?>",
                        data: $('#uom-form').serialize(),
                        dataType: 'json',
                        success: function(data){
                           if(data[0].error != 1){
                                notifymsg("success",". . .Units of Measure Added Successfully");
                                close_add(); active_search();
                           }else{
                            notifymsg("danger",data[0].msg);
                           }
                        },
                        complete: function() {

                        },
                        beforeSend: function(){
                           
                        }
                    });
                 }
             });

            function alert_cancel(){
              if($('#uom_cn').val() != "" || $('#uom_c').val() != "" || $('#uom_n').val() != "" || $('#uom_cb').is(':checked') == false){
                                                swal({
                                                      title: "Are you sure?",
                                                      text: "Your work will not be save",
                                                      type: "warning",
                                                      showCancelButton: true,
                                                      confirmButtonColor: "#DD6B55",
                                                      confirmButtonText: "Leave",
                                                      cancelButtonText: "Stay",
                                                      closeOnConfirm: true,
                                                      closeOnCancel: true },
                                                  function (isConfirm) {
                                                      if (isConfirm) {
                                                        swal("success");
                                                          close_add(); active_search();
                                                          notifymsg("hide","hide");
                                                      } else {
                                                          swal("Cancelled");
                                                      }
                                                  });
                            }else{
                                close_add(); active_search();
                                notifymsg("hide","hide");
                            }
            }
            $('#cancel_add').click(function(){
                alert_cancel();
            });




    $('#addX').click(function(){
            alert_cancel();      
       });
    });
 </script>  